var path = require("path");
var webpack = require("webpack");
var ExtractTextPlugin = require("extract-text-webpack-plugin");
var OptimizeCssAssetsPlugin = require("optimize-css-assets-webpack-plugin");
const baseConfig = require("./webpack.base.config");
const merge = require("webpack-merge");
module.exports = merge.merge(baseConfig, {
    entry: "./packages/index.js",
    output: {
        path: path.resolve(__dirname, "./dist"),
        filename: "index.es.min.js",
        chunkFilename: "[id].js",
        libraryExport: "default",
        library: "vue-keyboard-cn",
        libraryTarget: "umd",
    },
    devtool: "hidden-source-map",
});

if (process.env.NODE_ENV === "production") {
    module.exports.devtool = "#source-map";
    // http://vue-loader.vuejs.org/en/workflow/production.html
    module.exports.plugins = (module.exports.plugins || []).concat([
        new webpack.DefinePlugin({
            "process.env": {
                NODE_ENV: '"production"',
            },
        }),
        new ExtractTextPlugin("index.css"),
        new OptimizeCssAssetsPlugin({
            cssProcessor: require("cssnano"),
            cssProcessorOptions: { safe: true, discardComments: { removeAll: true } },
            canPrint: true,
        }),
        new webpack.optimize.UglifyJsPlugin({
            sourceMap: false,
            compress: {
                warnings: false,
                drop_debugger: true,
                drop_console: true,
                pure_funcs: ["console.log"], //移除console
            },
        }),
        new webpack.LoaderOptionsPlugin({
            minimize: true,
        }),
    ]);
}